package us.wili.dev.common.model;

import io.swagger.annotations.ApiModelProperty;

import javax.validation.constraints.Min;

/**
 * Created by JasonY on 17/6/14.
 */
public class PagerDto {

    public final static long DEFAULT_PAGE_NO = 1;
    public final static long DEFAULT_PER_PAGE = 10;
    @ApiModelProperty(value="页码")
    @Min(value = 1, message = "页码必须为正整数")
    private Long page;
    @ApiModelProperty(value="每页条数")
    @Min(value = 1, message = "每页条数必须为正整数")
    private Long count;

    private Long total;

    public PagerDto() {}

    public PagerDto(Long page, Long count) {
        this.page = page;
        this.count = count;
    }

    public Long getPage() {
        return this.page == null || this.page <= 0 ? DEFAULT_PAGE_NO : this.page;
    }

    public void setPage(Long page) {
        this.page = page;
    }

    public Long getCount() {
        return this.count == null || this.count <= 0L ? DEFAULT_PER_PAGE : this.count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    public Long getTotal() {
        return this.total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public long getOffset() {
        return (getPage() - 1) * getCount();
    }

    public long calTotalPage() {
        return this.total % getCount() == 0 ? total / getCount() : total / getCount() + 1;
    }
}
